package com.itheima.device.controller;


import com.itheima.device.pojo.Device;
import com.itheima.device.pojo.DeviceIndex;
import com.itheima.device.requetbodypackage.annotation.MultiRequestBody;
import com.itheima.device.service.DeviceIndexService;
import com.itheima.entity.Result;
import com.itheima.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/deviceIndex")
public class DeviceIndexController {
    @Autowired
    private DeviceIndexService deviceIndexService;


    @GetMapping("/findAll")
    public Result findAll(){
        List<DeviceIndex> deviceIndexList = null;
        try {
            deviceIndexList = deviceIndexService.findAll();
            return new Result(true, StatusCode.OK,"查询成功",deviceIndexList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"查询失败");
        }


    }

    /**
     * 根据设备id删除设备与设备指标
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteDeviceIndexDevice(@PathVariable Integer id){
        try {
            deviceIndexService.delete(id);
            return  new Result(true,StatusCode.OK,"删除设备与指标成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false,StatusCode.ERROR,"删除设备与指标失败");
        }

    }

    /**
     * 添加设备与设备指标
     *
     */
    @PostMapping("/add")
    public Result addDeviceIndexDevice(@RequestBody Device device){
        try {
            deviceIndexService.add(device);
            return new Result(true,StatusCode.OK,"添加设备与设备指标成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,StatusCode.ERROR,"添加设备与设备指标失败");
        }
    }








}
